package de.haw.shc.Control;

import de.haw.shc.R;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ControlPanel_frg extends ListFragment {
	OnItemSelectedListener mListner;
	private int selectedView = 0;
	
	public interface OnItemSelectedListener{
		public static int ROOM_VIEW = 0;
		public static int DEVICE_VIEW = 1;
		
		public String[] getData(int view);
		public void OnItemSelected(String itemKey);
	}
	
	@Override
	public void onAttach(Activity activity){
		super.onAttach(activity);
		try{
			mListner = (OnItemSelectedListener) activity;
		}catch(ClassCastException e){
			throw new ClassCastException(activity.toString()+" must implement OnItemSelectedListener Interface");
		}
	}
	
	@Override
	public void onListItemClick(ListView l, View v, int position, long id){
		super.onListItemClick(l, v, position, id);
		mListner.OnItemSelected((String)getListAdapter().getItem(position));
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.control_panel, container, false);
		return v;
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
	    super.onActivityCreated(savedInstanceState);
	    
	    String[] values = mListner.getData(selectedView);
	    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
	        android.R.layout.simple_list_item_1, values);
	    setListAdapter(adapter);
	  }
}
